#include "registerwindow.h"
#include "ui_registerwindow.h"

#include <QMouseEvent>
#include <QApplication>

RegisterWindow::RegisterWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::RegisterWindow)
{
    ui->setupUi(this);

    initUI();
}

RegisterWindow::~RegisterWindow()
{
    delete ui;
}

void RegisterWindow::initUI(){
    setCentralWidget(ui->widget_1);
    ui->gridLayout_4 = new QGridLayout(ui->widget_1);
}

void RegisterWindow::mousePressEvent(QMouseEvent *event){
    if(event->button() == Qt::LeftButton){  //event->button()用于获取触发事件的鼠标按键,Qt::LeftButton是左键
        pull = true;
        pulls = event->pos(); //鼠标相对于窗口的位置
    }
    QMainWindow::mousePressEvent(event); //处理完自定义逻辑后按父类规则处理
}
void RegisterWindow::mouseMoveEvent(QMouseEvent *event){
    if(pull && (event->buttons() & Qt::LeftButton)){  //判断正在用左键拖拽
        QPointF pos = event->globalPosition();
        // 如果你需要QPoint类型，可以转换一下
        QPoint newPos = pos.toPoint() - pulls;//计算拖拽后的位置
        move(newPos);
    }
    QMainWindow::mouseMoveEvent(event);
}
void RegisterWindow::mouseReleaseEvent(QMouseEvent *event){
    if(event->button() == Qt::LeftButton){  //停止拖拽
        pull = false;
    }
    QMainWindow::mouseReleaseEvent(event);
}

void RegisterWindow::on_stop_clicked()
{
    QApplication::exit();
}

